import fetch from '../config/fetch'

import * as login from './tempdata/login'


/**
 * 创建临时数据
 */
const setpromise = data => {
	return new Promise((resolve, reject) => {
		resolve(data)
	})
}

//编译环境使用真实数据
if (process.env.NODE_ENV == 'development') {

	/**
	 * 获取首页默认地址
	 */
	var cityGuess = () => fetch('GET', '/v1/cities', {
		type: 'guess'
	});
	/**
	 * 获取当前所在城市
	 */
	var currentcity = number => fetch('GET', '/v1/cities/' + number, {});
	/**
	 * 获取搜索地址
	 */

	var searchplace = (cityid, value) => fetch('GET', '/v1/pois', {
		type: 'search',
		city_id: cityid,
		keyword: value
	});
	/**
	 * 获取msite商铺列表
	 */

	var shopList = (latitude, longitude, offset, restaurant_category_id = '', restaurant_category_ids = '', order_by = '', delivery_mode = '', support_ids = []) => {
		let supportStr = '';
		support_ids.forEach(item => {
			if (item.status) {
				supportStr += '&support_ids[]=' + item.id;
			}
		});
		let data = {
			latitude,
			longitude,
			offset,
			limit: '20',
			'extras[]': 'activities',
			keyword: '',
			restaurant_category_id,
			'restaurant_category_ids[]': restaurant_category_ids,
			order_by,
			'delivery_mode[]': delivery_mode + supportStr
		};
		return fetch('GET', '/shopping/restaurants', data);
	};
	/**
	 * 账号密码登陆
	 */
	var accountLogin = (username, password, captcha_code) => fetch('POST', '/v2/login', {username, password, captcha_code});
	/**
	 * 检测帐号是否存在
	 */

	var checkExsis = (checkNumber, type) => fetch('GET', '/v1/users/exists', {
		[type]: checkNumber,
		type
	});
	/**
	 * 发送帐号
	 */
	var sendMobile = (sendData, captcha_code, type, password) => fetch('POST', '/v1/mobile/verify_code/send', {
		action: "send",
		captcha_code,
		[type]: sendData,
		type: "sms",
		way: type,
		password,
	});
	/**
	 * 重新发送订单验证码
	 */

	var rePostVerify = (cart_id, sig, type) => fetch('POST', '/v1/carts/' + cart_id + '/verify_code', {
		sig,
		type,
	});
	/**
	 * 获取用户信息
	 */

	var getUser = () => fetch('GET', '/v1/user', {});
	// /**
	//  * 获取订单列表
	//  */

	var getOrderList = (user_id, offset) => fetch('GET', '/bos/v2/users/' + user_id + '/orders', {
		limit: 10,
		offset,
	});
	/**
	* 删除地址
	*/

	var deleteAddress=(userid, addressid) => fetch('DELETE','/v1/users/' + userid + '/addresses/' + addressid,{})
  /**
   *个人中心里编辑地址
   */

  var getAddressList = (user_id) => fetch('GET', '/v1/users/'+user_id+'/addresses')
  /**
   * 验证码图片
   * @returns {Promise<*>}
   */
  var getcaptchas = () => fetch('POST', '/v1/captchas', {});

}else{
  var cityGuess = () => setpromise(home.guesscity);
  var hotcity = () => setpromise(home.hotcity);
  var groupcity = () => setpromise(home.groupcity);
  var currentcity = number => setpromise(city.currentcity);
  var searchplace = (cityid, value) => setpromise(city.searchdata);
  var msiteAdress = geohash => setpromise(msite.msiteAdress);
  var msiteFoodTypes = geohash => setpromise(msite.foodTypes);
  var shopList = (latitude, longitude, offset) => setpromise(msite.shopList);
  var searchRestaurant = (geohash, keyword) => setpromise(search.searchData);
  var foodCategory = (latitude, longitude) => setpromise(food.category);
  var foodDelivery = (latitude, longitude) => setpromise(food.delivery);
  var foodActivity = (latitude, longitude) => setpromise(food.activity);
  var shopDetails = (shopid, latitude, longitude) => setpromise(shop.shopDetails);
  var foodMenu = restaurant_id => setpromise(shop.shopMenu);
  var getRatingList = (offset, tag_name = '') => setpromise(shop.ratingList);
  var ratingScores = shopid => setpromise(shop.scores);
  var ratingTags = shopid => setpromise(shop.tage);
  var mobileCode = phone => setpromise(login.validate_token);
  var accountLogin = (username, password, captcha_code) => setpromise(login.userInfo);
  var checkExsis = (checkNumber, type) => setpromise(login.checkExsis);
  var sendMobile = (sendData, captcha_code, type, password) => setpromise(login.send);
  var checkout = (geohash, entities) => setpromise(confirm.checkout);
  var getRemark = (id, sig) => setpromise(confirm.remark);
  var getAddress = (id, sig) => setpromise(confirm.addressList);
  var getcaptchas = () => setpromise(login.cpatchs);
  var searchNearby = keyword => setpromise(confirm.searchAddress);
  var postAddAddress = (userId, address, address_detail, geohash, name, phone, phone_bk, poi_type, sex, tag, tag_type) => setpromise(confirm.addAddress);
  var placeOrders = (user_id, cart_id, address_id, description, entities, geohash, sig) => setpromise(confirm.palceOrder);
  var rePostVerify = (cart_id, sig, type) => setpromise(confirm.verfiyCode);
  validateOrders = ({
                      user_id,
                      cart_id,
                      address_id,
                      description,
                      entities,
                      geohash,
                      sig,
                      validation_code,
                      validation_token
                    }) => setpromise(confirm.orderSuccess);
  var payRequest = (merchantOrderNo, userId) => setpromise(confirm.payDetail);
  getService = () => setpromise(service.serviceData);
  var vipCart= (id, number, password) => setpromise(vip.vipcart);
  var getHongbaoNum= id => setpromise(hongbao.dataList);
  var getExpired= id => setpromise(hongbao.expired);
  var exChangeHongbao= (id, exchange_code, captcha_code) => setpromise(hongbao.exchange);
  var getUser = () => setpromise(login.userInfo);
  var getOrderList = (user_id, offset) => setpromise(order.orderList);
  var getOrderDetail = (user_id, orderid) => setpromise(order.orderDetail);
  var getAddressList = (user_id) => setpromise(addresspart.address);
  var getSearchAddress=(keyword) => setpromise(addDetail.addData);
  var deleteAddress=(userid, addressid) =>  setpromise(vip.vipcart);


}
//测试数据
/**
 * 短信验证码
 * @param phone
 * @returns {*}
 */
var mobileCode = phone => setpromise(login.validate_token);
/**
 * 用户
 * @param code
 * @param mobile
 * @param validate_token
 * @returns {*}
 */
var sendLogin = (code, mobile, validate_token) => setpromise(login.userInfo);
export {cityGuess, hotcity, groupcity, currentcity, searchplace, msiteAdress, msiteFoodTypes,shopList, searchRestaurant, foodCategory, foodDelivery, foodActivity, shopDetails, foodMenu, getRatingList, ratingScores, ratingTags, mobileCode, accountLogin, checkExsis, sendMobile, checkout, getRemark, getAddress, getcaptchas, searchNearby, postAddAddress, placeOrders, rePostVerify, payRequest, vipCart, getHongbaoNum, getExpired, exChangeHongbao, getUser, sendLogin, getOrderList, getOrderDetail, getAddressList, getSearchAddress, deleteAddress}
